/**
 * 
 */
package optimization.naturalOptimization.evolutionaryAlgorithm.evolutionaryOperator.recombination;

import optimization.naturalOptimization.evolutionaryAlgorithm.EvolutionaryAlgorithm;
import optimization.naturalOptimization.population.individual.EA.EAIndividual;

/**
 * This class supports the recombination, in which the individuals of the parent
 * generation are copied and added to progeny generation.
 * 
 * @author Kevin Wagner
 * @version 1.0
 */
public class CopyRecombination extends Recombinator {

	/**
	 * Creates a new copy recombinator.
	 * 
	 * @param parentEA
	 */
	public CopyRecombination(EvolutionaryAlgorithm parentEA) {
		super(parentEA);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * optimization.naturalOptimization.evolutionaryAlgorithm.evolutionaryOperator
	 * .EvolutionaryOperator#work()
	 */
	@SuppressWarnings("rawtypes")
	@Override
	public void work() {
		for (int i = 0; i < getParentEA().getLambda(); i++) {
			int rndNumber=getParentEA().getRng().nextInt(getParentEA().getMu());
			EAIndividual newInd = ((EAIndividual) getParentEA()
					.getParentPopulation().getIndividual(rndNumber)).clone();
			newInd.setParentPopulation(getParentEA().getProgenyPopulation());
			getParentEA().getProgenyPopulation().addIndividual(newInd);
		}

	}

}
